package com.drore.cloud.sdkjdbc.Jdbc;


import com.drore.cloud.sdkjdbc.exception.DataSdkException;
import com.drore.cloud.sdkjdbc.model.SqlParameter;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/***
 * 浙江卓锐科技股份有限公司 版权所有@Copyright 2016
 * 说明
 * 项目名称
 * @since:cloud-ims 1.0
 * @author <a href="mailto:baoec@drore.com">baoec@drore.com </a> 
 * 2018/06/21 17:11
 */

public class JDBCStatement {
    public  static Object setObject(Object parameterObj){
        if(parameterObj == null) {
            return null;
        } else if(parameterObj instanceof String) {
            return "'"+(String)parameterObj+"'";
        } else if(parameterObj instanceof Integer) {
            return (Integer)parameterObj;
        }
        return null;
    }
    public static PreparedStatement setParams(PreparedStatement stmt,List<SqlParameter> lists) throws SQLException {
        int i=1;
        for (SqlParameter obj : lists) {
            if(obj.getParamType().equals("term")){
                stmt.setObject(i,obj.getParamValue());
            }else if(obj.getParamType().equals("rangeOne")){
                stmt.setObject(i,obj.getParamValue());
            }else if(obj.getParamType().equals("rangeTwo")){
                stmt.setObject(i,obj.getParamValue());
            }else if(obj.getParamType().equals("fuzzy")){
                stmt.setObject(i,"%"+obj.getParamValue()+"%");
            }else {
                throw new DataSdkException("还没这种情况 谢谢");
            }
            i++;
        }
        return stmt;
    }


}
